
// Source File Name:   OIDImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.LIST_INT;
import com.sunwayhorizo.health.hl7.datatypes.OID;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;
import com.sunwayhorizo.health.hl7.datatypes.UID;
import com.sunwayhorizo.health.hl7.datatypes.common.gtsparser.OIDParser;
import com.sunwayhorizo.health.hl7.datatypes.common.gtsparser.ParseException;

import java.io.StringReader;


//            STCommonImpl, ANYImpl, BLImpl, CSImpl,
//            INTImpl, LIST_INTAdapterImpl, TYPEImpl, UIDImpl

public class OIDImpl extends STCommonImpl
    implements OID
{

    public static final String RCS_ID = "$Header: OIDImpl.java 1.0 2006/09/16 10:39:35 mmoores noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: OIDImpl.java 1.0 2006/09/16 10:39:35 mmoores noship $", "com.sunwayhorizo.health.hl7.datatypes.common");
    protected INT mLeaf;
    protected LIST_INT mButLeaf;
    private static final OID nullNI = new OIDImpl(CSImpl.valueOf("NI"));
    private static final OID nullOTH = new OIDImpl(CSImpl.valueOf("OTH"));
    private static final OID nullNINF = new OIDImpl(CSImpl.valueOf("NINF"));
    private static final OID nullPINF = new OIDImpl(CSImpl.valueOf("PINF"));
    private static final OID nullUNK = new OIDImpl(CSImpl.valueOf("UNK"));
    private static final OID nullASKU = new OIDImpl(CSImpl.valueOf("ASKU"));
    private static final OID nullNAV = new OIDImpl(CSImpl.valueOf("NAV"));
    private static final OID nullMSK = new OIDImpl(CSImpl.valueOf("MSK"));
    private static final OID nullNA = new OIDImpl(CSImpl.valueOf("NA"));
    private static final OID nullNASK = new OIDImpl(CSImpl.valueOf("NASK"));

    public static OID valueOf(String s)
    {
        StringReader stringreader = new StringReader(s);
        OIDParser oidparser = new OIDParser(stringreader);
        OID oid;
        try
        {
            oid = oidparser.oid(s);
            UIDImpl.checkParserState(oidparser);
        }
        catch(ParseException parseexception)
        {
            throw new IllegalArgumentException(parseexception.toString());
        }
        return oid;
    }

    public OIDImpl(INT int1, LIST_INT list_int, String s)
    {
        super(s);
        mLeaf = int1;
        mButLeaf = list_int;
    }

    protected OIDImpl(String s)
    {
        super(s);
        throw ANYImpl.newUnsupportedException("OID", "constructor");
    }

    protected OIDImpl(CS cs)
    {
        super(cs);
        mLeaf = INTImpl.nullINT(cs);
        mButLeaf = LIST_INTAdapterImpl.nullLIST_INT(cs);
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.OID;
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof UID))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            UID uid = (UID)any;
            return BLImpl.valueOf(stringValue().equals(uid.stringValue()));
        }
    }

    public INT leaf()
    {
        throw ANYImpl.newUnsupportedException("OID", "leaf");
    }

    public OID butLeaf()
    {
        throw ANYImpl.newUnsupportedException("OID", "butLeaf");
    }

    public OID value(OID oid)
    {
        throw ANYImpl.newUnsupportedException("OID", "value");
    }

    public static OID nullOID(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

	public byte[] byteArray() {
		// TODO Auto-generated method stub
		return null;
	}

}
